clear 

use ElectoralStudies_Replication_dataset, clear


*********************************************************************************************************************
*Table 1:
proportion gndr if samesexrelationship==1 & inarelationship==1
proportion gndr if samesexrelationship==0 & inarelationship==1

mean agea if samesexrelationship==1 & inarelationship==1
mean agea if samesexrelationship==0 & inarelationship==1

mean eduyrs if samesexrelationship==1 & inarelationship==1
mean eduyrs if samesexrelationship==0 & inarelationship==1

mean hincfel if samesexrelationship==1 & inarelationship==1
mean hincfel if samesexrelationship==0 & inarelationship==1

mean rlgdgr if samesexrelationship==1 & inarelationship==1
mean rlgdgr if samesexrelationship==0 & inarelationship==1

mean domicil if samesexrelationship==1  & inarelationship==1
mean domicil if samesexrelationship==0 & inarelationship==1

mean stfeco if samesexrelationship==1 & inarelationship==1
mean stfeco if samesexrelationship==0 & inarelationship==1

mean stfdem if samesexrelationship==1 & inarelationship==1
mean stfdem if samesexrelationship==0 & inarelationship==1
*********************************************************************************************************************





*********************************************************************************************************************
*Table 2
set more off
mlogit PartyGroups i.samesexrelationship gndr agea eduyrs hincfel rlgdgr domicil stfeco stfdem if inarelationship==1, vce(cluster countryyear)
*********************************************************************************************************************





*********************************************************************************************************************
*Figure 2
margins, dydx(samesexrelationship) at(gndr=2) atmeans predict(outcome(1))
marginsplot, name(FarLeft, replace)

margins, dydx(samesexrelationship) at(gndr=2) atmeans predict(outcome(2))
marginsplot, name(Green, replace)

margins, dydx(samesexrelationship) at(gndr=2) atmeans predict(outcome(3))
marginsplot, name(CenterLeft, replace)

margins, dydx(samesexrelationship) at(gndr=2) atmeans predict(outcome(4))
marginsplot, name(CenterRight, replace)

margins, dydx(samesexrelationship) at(gndr=2) atmeans predict(outcome(5))
marginsplot, name(FarRight, replace)

margins, dydx(samesexrelationship) at(gndr=2) atmeans predict(outcome(6))
marginsplot, name(Liberal, replace)

graph combine FarLeft Green CenterLeft CenterRight FarRight Liberal, ycommon rows(1) name(Differences, replace)

set more off
mlogit PartyGroups i.samesexrelationship gndr agea eduyrs hincfel rlgdgr domicil stfeco stfdem if inarelationship==1, vce(cluster countryyear) 

margins samesexrelationship, at(gndr=2) atmeans predict(outcome(1))
marginsplot, name(FarLeft, replace) 
margins samesexrelationship, at(gndr=2) atmeans predict(outcome(2))
marginsplot, name(Green, replace)
margins samesexrelationship, at(gndr=2) atmeans predict(outcome(3))
marginsplot, name(CenterLeft, replace)
margins samesexrelationship, at(gndr=2) atmeans predict(outcome(4))
marginsplot, name(CenterRight, replace)
margins samesexrelationship, at(gndr=2) atmeans predict(outcome(5))
marginsplot, name(FarRight, replace)
margins samesexrelationship, at(gndr=2) atmeans predict(outcome(6))
marginsplot, name(Liberal, replace)
graph combine FarLeft Green CenterLeft CenterRight FarRight Liberal, ycommon rows(1) name(PointEstimates, replace)

graph set window fontface "Times New Roman"

graph combine PointEstimates Differences, rows(2) name(Figure2, replace)
*********************************************************************************************************************


 
 
 
 
 
 
 
 
 
 
*********************************************************************************************************************
*Figure 1
#delimit ;
hist PartyGroups if samesexrelationship==1 & inarelationship==1, 
scheme(s1mono) barwidth(.5) percent name(G17, replace) ylabel(0(5)45) 
xlabel(1 "Far Left" 2 "Greens" 3 "Center Left" 4 "Liberals" 5 "Center Right" 6 "Far Right", angle(45)) title("LGBs")
;
#delimit cr

#delimit ;
hist PartyGroups if samesexrelationship==0  & inarelationship==1, 
scheme(s1mono) barwidth(.5) percent name(G27, replace) ylabel(0(5)45) 
xlabel(1 "Far Left" 2 "Greens" 3 "Center Left" 4 "Liberals" 5 "Center Right" 6 "Far Right", angle(45)) title("non-LGBs")
;
#delimit cr

#delimit ;
graph combine G17 G27, row(1) scheme(s1mono) xsize(8) ysize(4) 
title("Histogram of party vote in the last election by LGB and non-LGB", size(med)) name(LGB1, replace)
;
#delimit cr
 
 

collapse (mean) meanpiddum1=samesexrelationship (seb) sepiddum1=samesexrelationship if inarelationship==1, by(PartyGroups)

*calculating the confidence intervals 
gen hidem = meanpiddum1 + 1.96*sepiddum1
gen lodem = meanpiddum1 - 1.96*sepiddum1

#delimit ;
graph twoway (bar meanpiddum1 PartyGroups, fcolor(black) barwidth(.5) fcolor(gs10)) 
(rcap lodem hidem PartyGroups, color(black)), 
ylabel(0(.01).03) xlabel(1 "Far Left" 2 "Greens" 3 "Center Left" 4 "Liberals" 5 "Center Right" 6 "Far Right") scheme(s1mono) 
ytitle("Pr(LGB)")
title("Proportion LGB by Party Vote with 95 percent confidence intervals", size(med))
ysize(1) xsize(1.6)
legend(off) name(LGB2, replace)
;
#delimit cr

graph set window fontface "Times New Roman"


graph combine LGB1 LGB2, rows(2) note("Data source: European Social Survey 2002-2018") scheme(s1mono) ysize(8) xsize(7) title("Figure 1: Descriptive Statics by LGBs and Party Voting", size(med)) name(Figure1, replace)
*********************************************************************************************************************





